<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>考勤系统登录</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css">
</head>
<body>
<h1 align="center">考勤系统登陆页面</h1>
</br>
</br>
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="title" id="login_username" required lay-verify="required" placeholder="请输入用户名"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-inline">
                <label for="login_userpswd"></label><input type="password" name="password" id="login_userpswd" required
                                                           lay-verify="required"
                                                           placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div style="text-align:center">
            <button class="layui-btn" onclick="login()" id="" lay-submit lay-filter="formDemo">登陆</button>
        </div>
    </div>
</div>
<script src="/lib/layui/layui.js"></script>
<script>

    function login() {
        layui.use(['table'], function () {
            var $ = layui.jquery;
            var params = {};
            params.usernum = $('#login_username').val();
            params.pswd = $('#login_userpswd').val();
            $.ajax({
                type: "POST",
                url: "/user/login",
                dataType: "json",
                contentType: "application/json; charset=UTF-8",
                data: JSON.stringify(params),
                success: function (result) {
                    //绑定数据
                    if (result.status === 200) {
                        sessionStorage.setItem("login_username", result.data.user.usernum);
                        location.reload();
                    } else {
                        alert(result.data.error)
                    }
                }
            })
        })
    }
</script>

</body>
</html>
<style>
    .layui-form-item {
        text-align: center;
    }

    .layui-inline {
        text-align: center;
    }

    .layui-btn {
        text-align: center;
    }

</style>